package service;

import dao.SalesOrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Customer;
import pojo.SalesOrder;

import java.sql.Date;
import java.util.List;

@Service
public class SalesOrderService {
    @Autowired
    SalesOrderDao salesOrderDao;

    public SalesOrder queryOrder(int id){
        return salesOrderDao.queryOrder(id);
    }

    public List<SalesOrder> getAllOrder(){
        return salesOrderDao.queryAllOrder();
    }


    public int addOrder(SalesOrder salesOrder,int customerId){
        salesOrderDao.addOrder(salesOrder);
        Customer customer = new Customer();
        customer.setId(customerId);
        customer.setOrderId(salesOrder.getId());
        return salesOrderDao.updateCustomer(customer);
    }

    public int updateOrder(SalesOrder salesOrder){
        return salesOrderDao.updateOrder(salesOrder);
    }

    public int deleteOrder(int id){
        return salesOrderDao.deleteOrder(id);
    }

    public int sumOrderByTime(String s,String e){
        int num = 0;
        List<SalesOrder> list = salesOrderDao.queryOrderByStartTime(s, e);
        for(int i = 0; i < list.size(); i++){
            num += list.get(i).getServiceId() == 1 ? 188 : 50;
        }
        return num;
    }

    public List<SalesOrder> getOrderByEndTime(String s,String e){
        return salesOrderDao.queryOrderByEndTime(s,e);
    }

}
